package com.sumainfor.pc.epc.controller.buyer;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.epc.service.HousingConfigChangeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 房源配置变更
 *
 * @Author PuaChen
 * @Create 2018-12-03 18:31
 */
@RestController
@RequestMapping("/housing/config")
public class HousingConfigChangeController {

    @Autowired
    private HousingConfigChangeService hcc;

    /**
     * 查询列表
     *
     * @param page
     * @param params
     * @return
     */
    @RequestMapping("/selectConfigList")
    public JsonResult selectConfigList(Page page, @RequestParam Map<String, Object> params) {
        if (!FieldCheckUtil.isMapFieldNotNull(params, "state")) {
            return JsonResult.errorForEmpty();
        }
        return hcc.selectConfigList(page, params);
    }

    /**
     * 获得 房源配置变更详情数据
     *
     * @param confId
     * @return
     */
    @RequestMapping("/getConfigInfo")
    public JsonResult getConfigInfo(String confId) {
        if (StringUtils.isBlank(confId)) {
            return JsonResult.errorForEmpty();
        }
        return hcc.getConfigInfo(confId);
    }

    /**
     * 根据商品的名称 和 规格的名称 + 商品的类型int 查询关联的品牌商品列表
     *
     * @param params
     * @return
     */
    @RequestMapping("/getSpinnerForBrandList")
    public JsonResult getSpinnerForBrandList(@RequestParam Map<String, String> params) {
        if (!FieldCheckUtil.isMapFieldNotNull(params, "ComName", "ComSpeName", "ComType")) {
            return JsonResult.errorForEmpty();
        }
        return hcc.getSpinnerForBrandList(params);
    }

    /**
     * 根据 商品的ID 和规格的名称去查询型号表的所有的信息
     *
     * @param shopId
     * @param speName
     * @return
     */
    @RequestMapping("/getSpinnerForMoList")
    public JsonResult getSpinnerForMoList(String shopId, String speName) {
        if (StringUtils.isBlank(shopId) || StringUtils.isBlank(speName)) {
            return JsonResult.errorForEmpty();
        }
        return hcc.getSpinnerForMoList(shopId, speName);
    }

    /**
     * 通过型号的编号 查出来所有的供应商
     *
     * @param moId
     * @return
     */
    @RequestMapping("/getSupplierAndPrice")
    public JsonResult getSupplierAndPrice(String moId) {
        if (StringUtils.isBlank(moId)) {
            return JsonResult.errorForEmpty();
        }
        return hcc.getSupplierAndPrice(moId);
    }

    /**
     * 出库的操作
     *
     * @param params
     * @return
     */
    @PostMapping("/outPutStock")
    public JsonResult outPutStock(@RequestParam Map<String, Object> params) {
        if (!FieldCheckUtil.isMapFieldNotNull(params, "moId", "count", "supId", "id")) {
            return JsonResult.errorForEmpty();
        }
        return hcc.outPutStock(params);
    }

    /**
     * 入库的操作
     *
     * @param params
     * @return
     */
    @PostMapping("/inPutStock")
    public JsonResult inPutStock(@RequestParam Map<String, Object> params) {
        if (!FieldCheckUtil.isMapFieldNotNull(params, "removeCount", "id", "inCount")) {
            return JsonResult.errorForEmpty();
        }
        return hcc.inPutStock(params);
    }

    /**
     * 获得某一条数据的详情
     *
     * @param params
     * @return
     */
    @RequestMapping("/getItemInfo")
    public JsonResult getItemInfo(@RequestParam Map<String, Object> params) {
        if (!FieldCheckUtil.isMapFieldNotNull(params, "id")) {
            return JsonResult.errorForEmpty();
        }
        return hcc.getItemInfo(params);
    }

}
